package Services

import(
	"github.com/gin-gonic/gin"
	"fmt"
	"net/http"
	"gin/Common"
	"strconv"
)

type DisplayEntitySearchCgi struct {
	Common.CgiBase
}

func (cgi *DisplayEntitySearchCgi)querySuggest() (bool, string) {
	page,_ := strconv.Atoi(cgi.Input["page"])
	return Common.Search(cgi.Input["word"], 10, page, 1)
}

func (cgi *DisplayEntitySearchCgi)processParam(c *gin.Context) {
	cgi.Input["word"] = c.Query("word")
	cgi.Input["page"] = c.Query("page")
}

// 实体集数据
func DisplayEntitySearch(c *gin.Context) {
	fmt.Println("DisplayEntitySearch")
	var cgi DisplayEntitySearchCgi
	cgi.Init(c)
	cgi.processParam(c)

	res, data := cgi.querySuggest()
	if (!res) {
		c.JSON(http.StatusOK, gin.H{
	        "result": -1,
	        "msg":    "query fail",
	        "data": "{}",
	    })
	    return
	}

    c.JSON(http.StatusOK, gin.H{
        "result": 0,
        "msg":    "success",
        "data": data,
    })

}

